package net.display;

import javax.servlet.http.HttpServletRequest;

import net.bo.KPlan;
import net.bo.KUtilisateur;
import net.ko.displays.KObjectDisplay;
import net.ko.http.views.KPageList;
import net.ko.kobject.KObject;

public class DisplayPlansEnCours extends KObjectDisplay {

	@Override
	public void beforeLoading(Class<? extends KObject> clazz, KPageList list,
			HttpServletRequest request) {
		KUtilisateur user = (KUtilisateur) request.getSession().getAttribute("activeUser");
		Integer idUtilisateur = (Integer) user.getId();
		list.setSql("select plan.* from utilisateur inner join fTester on utilisateur.id=fTester.idUtilisateur inner join fonction on fTester.idFonction=fonction.id inner join rubrique on fonction.idRubrique=rubrique.id inner join plan on rubrique.idPlan=plan.id left outer join validation on plan.id=validation.idPlan where utilisateur.id="+idUtilisateur+" and validation.idPlan is null group by plan.id");
		/*if (user != null) {
			list.getKListObject().addAll(user.getPlans());
			list.setLoaded(true);
		}*/

		super.beforeLoading(clazz, list, request);
	}

	@Override
	public String showInList(KObject ko, String memberName, HttpServletRequest request) {
		String result = super.showInList(ko, memberName, request);
		KPlan plan = (KPlan) ko;
		if ("rubriques".equals(memberName)) {
			if (plan.getRubriques() != null)
				result = plan.getRubriques().showWithMask("<a id='{id}' class='rItem'>{libelle}</a><br />");
		}
		return result;
	}
}
